<?php

namespace Home\Controller;

use Think\Controller;
<<<<<<< HEAD
class IndexController extends Controller {


    public function index(){

        $this->display();
    }


    public function clubLogin(){

        $this->display();
    }


    public function adminlogin(){

        $this->display();
=======

class IndexController extends Controller
{

    //用户登陆
    public function index()
    {
        session('[start]');
        $this->display();
    }

    //生成验证码
    public function verify()
    {
        // 实例化Verify对象
        $verify = new \Think\Verify();

        // 配置验证码参数
        $verify->fontSize = 14;     // 验证码字体大小
        $verify->length = 4;        // 验证码位数
        $verify->imageH = 34;       // 验证码高度
        $verify->useImgBg = true;   // 开启验证码背景
        $verify->useNoise = false;  // 关闭验证码干扰杂点
        $verify->entry();
    }

    //登陆校验校验
    public function checkLogin()
    {
        $verify = new \Think\Verify();
        $code = I('post.verify');//表单验证码

        $uname = I('post.uname');//表单登录名
        $pwd = md5(I('post.pwd'));//表单密码

//        $rempwd = I('post.rempwd');

        $type = I('post.radio'); //登陆用户类型

        if ($type == 0) { //系统管理员登陆

            $systemAdmin = M('systemadmin');

            //判断密码正确性
            $systemAdminInfo = $systemAdmin->where("s_name='%s'",$uname)->select();
            $truePwd = $systemAdminInfo['0']['s_pwd'];
//            dump($truePwd);
            if($truePwd != $pwd){
                $this->error('密码错误');
            }

           //记录session
            $systemAdminId = $systemAdminInfo['0']['s_id'];
            session('systemAdminId',$systemAdminId);

        } else if ($type == 1) { //俱乐部管理员登陆

            $clubAdmin = M('clubadmin');

            //判断密码正确性
            $clubAdminInfo = $clubAdmin->where("c_phone='%s'",$uname)->select();
            $truePwd = $clubAdminInfo['0']['c_pwd'];
//            dump($truePwd);
            if($truePwd != $pwd){
                $this->error('密码错误');
            }

            $clubAdminId = $clubAdminInfo['0']['c_id'];
            session('clubAdminId',$clubAdminId);

        } else if($type == 2) { //教练登陆

            $coach = M('coach');

            //判断密码正确性
            $coachInfo = $coach->where("coach_name='%s'",$uname)->select();
            $truePwd = $coachInfo['0']['coach_pwd'];
//            dump($truePwd);
            if($truePwd != $pwd){
                $this->error('密码错误');
            }

            $coachId = $coachInfo['0']['coach_name'];
            session('$coachId',$coachId);

        }

        //校验验证码
        if ($verify->check($code)) {
            session('flag','true');
            $this->success('登陆成功','../Activity/activityList',3);
        } else {
            $this->error('验证码错误');
        }
    }

    //退出登录
    public function doLogOut(){
        session('[destroy]');
        redirect('../Index/index',1,'您已注销！');
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
    }


    public function checkadminlogin(){
        session('flag',null);
        $admin=M('admin');
        $map   =   array();
        /*var_dump($_POST);
        exit;*/
        $map['adminname']  = I('post.adminname');
        $map['password']   =I('post.password');
        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            session("adminname",$map['adminname']);
            dump($_SESSION);
            redirect(U('Activity/activity'));
        }
    }

    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize  = 3145728 ;// 设置附件上传大小
        $upload->exts     = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = "./Public/image/"; // 设置附件上传根目录
        $upload->savePath = ""; // 设置附件上传（子）目录
        $upload->autoSub = false;
        $upload->saveName = 'time';
        //$upload->savePath = ""
        $info = $upload->upload();  // 上传文件
        if(!$info) {
            $this->error($upload->getError());
        } else {
            return $info;
        }
    }




}